<div class="box-body table-responsive no-padding">
    <table class="table">
        <thead>
        <tr>
            @foreach($headers as $filed => $item)
                <th>{{ $item['title'] }}</th>
            @endforeach
        </tr>
        <tr style="color:#f56f9c">
            @foreach($headers as $filed => $item)
                @if($filed == 'report_date')
                    <td>TTL</td>
                @elseif($filed == 'return_rate')
                    <td>{{ getPercentage($total['return_num'],$total['sales_num']) }}</td>
                @elseif($filed == 'saleable_rate')
                    <td>{{ getPercentage($total['saleable_num'],$total['sales_num']) }}</td>
                @elseif($item['sumField'])
                    <td>{{ array_key_exists($filed,$total) ? $total[$filed] : '' }}</td>
                @else
                    <td></td>
                @endif
            @endforeach
        </tr>
        </thead>
        <tbody>
        @foreach($paginator as $row)
            <tr>
                <td><span style="font-size: 85%;padding: .2em 0 .3em;">{{ $row->report_date }}</span></td>
                <td>{{ $row->area->area ?? '' }}</td>
                <td>{{ $row->country->country ?? '' }}</td>
                <?php
                    //客诉
                $QComplaint = App\Models\Quality\QComplaint::query()->where([
                        'report_date' => $row->report_date,
                        'area_id' => $row->area_id,
                        'country_id' => $row->country_id,
                        'psku_id' => $row->psku_id,
                    ])->first();
                ?>
                <td>{{ !empty($QComplaint) ? App\Models\Quality\QComplaint::$_origin[$QComplaint->origin] : '' }}</td>
                <td>{{ $QComplaint->order_no ?? '' }}</td>
                <td>{{ $row->sku->psku_code ?? '' }}</td>
                <td><span style="font-size: 85%;padding: .2em 0 .3em;">{{ $row->sku->psku_cn ?? '' }}</span></td>
                <td><span style="font-size: 85%;padding: .2em 0 .3em;">{{ \App\Models\Product\ProductClassify::$_season[$row->sku->classify->season ?? 3] }}</span></td>
                <td><span style="font-size: 85%;padding: .2em 0 .3em;">{{ $row->sku->classify->title ?? '' }}</span></td>
                <td>{{ $row->sales_num }}</td>
                <td>{{ $row->return_num }}</td>
                <td>{{ getPercentage($row->return_num,$row->sales_num) }}</td>
                <td>{{ $row->saleable_num }}</td>
                <td>{{ getPercentage($row->saleable_num,$row->sales_num) }}</td>
                @php
                $all = 0;
                @endphp
                <td>
                    @if($row->size)
                    <table class="table">
                        <tbody>
                        @foreach($row->size as $ks => $size)
                            @php
                                $all += $size;
                            @endphp
                            <tr>
                                <td style="border: 1px solid #eceef1;">{{ $ks }}</td>
                                <td style="border: 1px solid #eceef1;">{{ $size }}</td>
                                <td style="border: 1px solid #eceef1;">{{ getPercentage($size,$row->sales_num) }}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    @else
                        --
                    @endif
                </td>
                <td>
                    @if($row->produce)
                    <table class="table">
                        <tbody>
                        @foreach($row->produce as $kp => $produce)
                            @php
                                $all += $produce;
                            @endphp
                            <tr>
                                <td style="border: 1px solid #eceef1;">{{ $kp }}</td>
                                <td style="border: 1px solid #eceef1;">{{ $produce }}</td>
                                <td style="border: 1px solid #eceef1;">{{ getPercentage($produce,$row->sales_num) }}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    @else
                        --
                    @endif
                </td>
                <td>
                    @if($row->design)
                    <table class="table">
                        <tbody>
                        @foreach($row->design as $kd => $design)
                            @php
                                $all += $design;
                            @endphp
                            <tr>
                                <td style="border: 1px solid #eceef1;">{{ $kd }}</td>
                                <td style="border: 1px solid #eceef1;">{{ $design }}</td>
                                <td style="border: 1px solid #eceef1;">{{ getPercentage($design,$row->sales_num) }}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    @else
                        --
                    @endif
                </td>
                <td>
                    @if($row->subject)
                    <table class="table">
                        <tbody>
                        @foreach($row->subject as $ksu => $subject)
                            @php
                                $all += $subject;
                            @endphp
                            <tr>
                                <td style="border: 1px solid #eceef1;">{{ $ksu }}</td>
                                <td style="border: 1px solid #eceef1;">{{ $subject }}</td>
                                <td style="border: 1px solid #eceef1;">{{ getPercentage($subject,$row->sales_num) }}</td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                    @else
                        --
                    @endif
                </td>
                <td>{{ getPercentage($all,$row->sales_num) }}</td>
            </tr>
        @endforeach
        </tbody>
    </table>
</div>
